package edu.ucsd.ccdb.tagPopup.util;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import edu.ucsd.ccdb.tagPopup.summaryPane.CCDBTagSummaryPane;
import edu.ucsd.ccdb.tagPopup.summaryPane.OnthoTagSummaryPane;
import edu.ucsd.irods.IRODSFileString;

public class SummaryPaneRefresher implements ActionListener {

	private Integer MPID;
	private IRODSFileString file;
	private JPanel paneToRefresh;
	private String username;
	
	public SummaryPaneRefresher ( String username, Integer MPID, IRODSFileString file, JPanel source) {
		this.username = username;
		this.MPID = MPID;
		this.file = file;
		this.paneToRefresh = source;		
	}
	
	public void actionPerformed(ActionEvent e) {
		doRefreshAction( username, MPID, file, paneToRefresh);
	}
	
	public static void doRefreshAction ( String username, Integer MPID, IRODSFileString file, JPanel pane ) {
		System.out.println ("Refreshing the summary panel ");
		pane.removeAll();
		
		// add the data back in
//		JLabel CCDBLabel = new JLabel("CCDB Labels: " + getDetailTabsOnSelectedFile(file.getAbsolutePath() ));
		JPanel CCDBPane = new CCDBTagSummaryPane( username, pane , MPID, file);
		
//		JLabel onthoLabel = new JLabel ("Ontho Label: N/A");
//		try {
//			onthoLabel = new JLabel ("Ontho Labels: " + SQLDBQuery.getDisplayOthoTag(MPID, file.getAbsolutePath(), IRODSConfiguration.LOGIN_USERNAME));
//		} catch (SQLException e1) {
//			e1.printStackTrace();
//		}

		JPanel onthoPane = new OnthoTagSummaryPane ( username, pane , MPID, file );
		
		pane.add(CCDBPane);
		pane.add(onthoPane);
		
		pane.revalidate();
		pane.repaint();
	}	
}
